package txtpack.Work;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Arrays;

public class Exam02 {
    public static void main(String[] args) {
        //将一个UTF-8编码的文件转换成一个GBK格式的文件，分别使用字节流和字符流实现。
        File target  = new File("E:\\IO流练习\\InoutStream\\utf8.txt");
        File dest = new File("E:\\IO流练习\\字符流\\FileWrite\\ByteGBK.txt");
       conversion(target,dest);
    }
    //字节流
    private static void conversion(File target ,File dest){
        try(FileInputStream in = new FileInputStream(target);
            FileOutputStream out = new FileOutputStream(dest)){
            byte[] bytes = in.readAllBytes();
            String str = new String(bytes);
            byte[] bytes1 = str.getBytes("GBK");
            out.write(bytes1);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
